package FILE;
import java.io.*;
import java.util.Scanner;
/*
 * Author: AMark
 * Date:10/30/2023
 * Time:8:09 AM
 */

public class Filedemo {
    public static void main(String[] args) {
        //打开文件
//        File folder = new File("D:");
//        String[] filename = folder.list();
//        for(int i = 0; i < filename.length; i++) {
//            System.out.println(filename[i]);
//        }
        //使用输入流
//        File myfile = new File("D:");
//        try {
//            FileOutputStream fos= new FileOutputStream(myfile);
//            for(int i = 0; i < 10; i++) {
//                fos.write(i);
//            }
//            fos.close();
//        } catch (FileNotFoundException e) {
//            throw new RuntimeException(e);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
        //文件写入
//        System.out.println("请输入一段文字");
//        Scanner sc = new Scanner(System.in);
//        String s = sc.nextLine();
//        FileNotFoundException e = new FileNotFoundException();
        //文件复制
        File sourceFile = new File("test.txt");
        File destFile = new File("dest.txt");
        //创建源文件输入流对象
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(sourceFile);
            fos = new FileOutputStream(destFile);
            System.out.println("正在复制文件");
            byte[] buf = new byte[1024];
            int count;
            while((count = fis.read(buf)) != -1){
                fos.write(buf, 0, count);
            }
            System.out.println("文件复制成功");
            fis.close();
            fos.close();
        } catch (FileNotFoundException ex) {
            throw new RuntimeException(ex);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
        //自动关闭流(自动调用close函数s),在try块的括号中输入资源的声明，后面的数据库编程和网络编程都可以使用这样的。
        //缓冲流可以实现一行一行读取内容
        try(InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr)){


        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
